package cn.kduck.code.module.service;

import cn.kduck.code.entity.service.Entity;
import cn.kduck.core.service.ValueMap;

import java.util.List;
import java.util.Map;

import static cn.kduck.code.module.service.Module.ModuleFieldEnum.*;

public class Module extends ValueMap {

    public Module() {
    }

    public Module(Map map) {
        if (map != null) {
            super.putAll(map);
        }
    }

    public void setModuleId(String moduleId) {
        super.put(MODULE_ID.getAttrName(), moduleId);
    }

    public String getModuleId() {
        return super.getValueAsString(MODULE_ID.getAttrName());
    }

    public void setModuleName(String moduleName) {
        super.put(MODULE_NAME.getAttrName(), moduleName);
    }

    public String getModuleName() {
        return super.getValueAsString(MODULE_NAME.getAttrName());
    }

    public void setPackageName(String packageName) {
        super.put(PACKAGE_NAME.getAttrName(), packageName);
    }

    public String getPackageName() {
        return super.getValueAsString(PACKAGE_NAME.getAttrName());
    }

    public void setModuleCode(String moduleCode) {
        super.put(MODULE_CODE.getAttrName(), moduleCode);
    }

    public String getModuleCode() {
        return super.getValueAsString(MODULE_CODE.getAttrName());
    }


    public void setBaseApiPath(String baseApiPath) {
        super.put(BASE_API_PATH.getAttrName(), baseApiPath);
    }

    public String getBaseApiPath() {
        return super.getValueAsString(BASE_API_PATH.getAttrName());
    }

    public void setRequirement(String requirement) {
        super.put(REQUIREMENT.getAttrName(), requirement);
    }

    public String getRequirement() {
        return super.getValueAsString(REQUIREMENT.getAttrName());
    }

    public void setEntityList(List<Entity> entityList) {
        super.put(ENTITY_LIST.getAttrName(), entityList);
    }

    public List<Entity> getEntityList() {
        return (List<Entity>) super.get(ENTITY_LIST.getAttrName());
    }

    public enum ModuleFieldEnum {
        MODULE_ID("MODULE_ID", "moduleId"), MODULE_NAME("MODULE_NAME", "moduleName"), PACKAGE_NAME("PACKAGE_NAME", "packageName"), MODULE_CODE("MODULE_CODE", "moduleCode"), BASE_API_PATH("BASE_API_PATH", "baseApiPath"), REQUIREMENT("REQUIREMENT", "requirement"), ENTITY_LIST("ENTITY_LIST", "entityList");
        private final String fieldName;
        private final String attrName;

        ModuleFieldEnum(String fieldName, String attrName) {
            this.fieldName = fieldName;
            this.attrName = attrName;
        }

        public String getFieldName() {
            return fieldName;
        }

        public String getAttrName() {
            return attrName;
        }
    }
}
